package cn.lumora.controller;

import cn.lumora.core.dto.ApiResponse;
import cn.lumora.pojo.CharacterBaseInfo;
import cn.lumora.service.CharacterBaseInfoService;
import cn.lumora.vo.CharacterBaseInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 角色相关控制器
 */
@RestController
@RequestMapping("/playerRole")
public class PlayerRoleController {

    private final CharacterBaseInfoService characterBaseInfoService;

    @Autowired
    public PlayerRoleController(CharacterBaseInfoService characterBaseInfoService) {
        this.characterBaseInfoService = characterBaseInfoService;
    }

    /**
     * 获取当前登录玩家关联的角色列表
     */
    @GetMapping("/getPlayerRoleList")
    public ApiResponse<List<CharacterBaseInfo>> getPlayerRoleList(HttpServletRequest request){
        String token = request.getHeader("Token");
        List<CharacterBaseInfo> characterBaseInfoList =characterBaseInfoService.getPlayerRoleList();
        return ApiResponse.success(characterBaseInfoList);
    }

    /**
     * 获取角色数据
     */
    @GetMapping("/getCharacterBaseInfo")
    public ApiResponse<CharacterBaseInfoVo> getCharacterBaseInfo(String characterId){
        CharacterBaseInfoVo characterBaseInfo = characterBaseInfoService.getCharacterBaseInfo(characterId);
        return ApiResponse.success(characterBaseInfo);
    }

    /**
     * 角色登录
     */
    @GetMapping("/login")
    public ApiResponse<String> login(String characterId){
        return ApiResponse.success(characterBaseInfoService.login(characterId));
    }

    /**
     * 新增角色
     */
    @GetMapping("/addCharacter")
    public ApiResponse<String> addCharacter(){
        return ApiResponse.success(characterBaseInfoService.addCharacter());
    }
}
